# -*- coding: utf-8 -*-

import tesseract

api = tesseract.TessBaseAPI()
a = api.Init(".","eng",tesseract.OEM_DEFAULT)
#a = api.Init(".","chi_sim",tesseract.OEM_DEFAULT)


L= api.GetInitLanguagesAsString()
print(L)

#初始化结果
print ('Init result:'+str(a)+'; \n0 is ok,-1 is failure')

#单行模式，还有其他模式
api.SetPageSegMode(tesseract.PSM_SINGLE_LINE)

#自动模式
#api.SetPageSegMode(tesseract.PSM_AUTO)


mImgFile = "tom1.jpeg"

#mImgFile =  "fnord.tif"
#mImgFile = "phototest.tif"
mBuffer=open(mImgFile,"rb").read()
result = tesseract.ProcessPagesBuffer(mBuffer,len(mBuffer),api)
print(mImgFile)
print (u"图片识别结果:"),result
#print 'Result: ' + unicode(result,'gbk') 
api.End()
